<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>信息采集-会员</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/resources/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/resources/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <script src="/resources/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/resources/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/resources/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="/resources/css/app.css">
    <script src="/resources/js/jquery.min.js"></script>

</head>

<body data-type="widgets">
<script src="/resources/js/theme.js"></script>
<div class="am-g tpl-g">
    <%--头部开始--%>
    <%@include file="header.jsp" %>
    <%--头部结束--%>


    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">开单流程第一步</div>
                            <small>确认宝宝信息</small>
                        </div>

                        <div class="widget-body  am-fr">

                            <!-- 编辑栏 -->
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <%--<button type="button" class="am-btn am-btn-default am-btn-success" data-am-modal="{target: '#addmodel', closeViaDimmer: 0}"><span class="am-icon-plus"></span> 新增</button>--%>
                                            <%--<button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>--%>
                                            <%--<button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>--%>
                                            <%--<button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>--%>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- 下拉框 -->
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="am-form-group tpl-table-list-select">
                                    <select id="searchType" data-am-selected="{btnSize: 'sm'}">
                                        <option value="vipno">会员卡号</option>
                                        <option value="phone">父母电话号码</option>
                                        <option value="pname">父母姓名</option>
                                        <option value="bname">宝宝姓名</option>
                                        <option value="fileno">纸质档案编号</option>
                                    </select>
                                </div>
                            </div>
                            <!-- 搜索框 -->
                            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                    <input type="text" id="searchContent" class="am-form-field ">
                                    <span class="am-input-group-btn">
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
                                                    type="button" id="searchinfoBtn"></button>
                                          </span>
                                </div>
                            </div>
                            <script>
                                $('#searchinfoBtn').click(function () {
                                    searchInfo();
                                });

                                $("body").keydown(function () {
                                    var hasFocus = $('#searchContent').is(':focus');
                                    if (event.keyCode == "13") {//keyCode=13是回车键
                                        if (hasFocus == true) {
                                            searchInfo();
                                        } else {
                                            alert("全局")
                                        }
                                    }
                                });

                                function checkValue(type, content) {
                                    if (content === null || content === undefined || content === '' || content.length === 0) {
                                        return false;
                                    }
                                    // var phoneRex = /^1[34578]\d{9}$/;
                                    var phoneRex =/^\d{3,}$/;
                                    var otherRex = /^\w+$/;
                                    var otherRex1 = /^[\u2E80-\u9FFF]+$/;
                                    if (content.length > 200) {
                                        alert("输入的数据过长");
                                        return false;
                                    }
                                    if (type == "phone") {
                                        //电话号码校验
                                        if (phoneRex.test(content)) {
                                            return true;
                                        } else {
                                            alert("请输入三个以上的数字")
                                        }
                                    } else {
                                        if (otherRex.test(content) || otherRex1.test(content)) {
                                            return true;
                                        } else {
                                            alert("请输入正确的信息")
                                        }
                                    }
                                    return false;
                                }
                                function setValue(res) {
                                    //纸质档案编号
                                    $("#fileNo").attr("value",res.babyInfo.fileNo);
                                    //宝宝姓名
                                    $(".babyName").attr("value",res.babyInfo.babyName);
                                    //宝宝图片
                                    $(".imagePhoto").attr("src",res.babyInfo.babyPhoto);
                                    //宝宝性别
                                    $(".babySex").val(res.babyInfo.babySex);
                                    //是否早产
                                    $(".premature").val(res.babyInfo.premature);
                                    //宝宝年龄
                                    $(".babyAge").attr("value",res.babyInfo.babyAge);
                                    //宝宝身高
                                    $(".babyHeight").attr("value",res.babyInfo.babyHeight);
                                    //宝宝体重
                                    $(".babyWeight").attr("value",res.babyInfo.babyWeight);
                                    //宝宝出生日期
                                    var time =new Date(res.babyInfo.babybirthday);
                                    var   year=time.getFullYear();
                                    var   month=time.getMonth()+1;
                                    var   date=time.getDate();
                                    var t=year+"-"+month+"-"+date;
                                    $(".birthday").attr("value",t);
                                    //喂养史
                                   // $(".feedHistory").attr("value",res.babyInfo.feedHistory);
                                    $(".feedHistory").val(res.babyInfo.feedHistory);
                                    //过敏史
                                    $(".allergyHistory").val(res.babyInfo.allergyHistory);
                                    //病史
                                    $(".sickHistory").val(res.babyInfo.sickHistory);
                                    //备注
                                    $(".babyNote").val(res.babyInfo.babyNote);
                                    //会员卡类型
                                    $(".vipcategory").val(res.vipCard.vipName);
                                    //会员卡号码
                                    $(".vipNo").val(res.vipInfo.vipNo);
                                    //父母姓名
                                    $(".pname").val(res.userInfo.userName);
                                    //父母电话
                                    $(".phone").val(res.userInfo.userTel);
                                   //用户id
                                    $("#userId").val(res.userInfo.id);
                                    //隐藏字段宝宝ID
                                    $("#babyId").attr("value",res.babyInfo.babyId);
                                    //卡余额或者剩余次数
                                    if (res.vipCard.vipLevel==0){
                                        //体验卡
                                        $(".vipSum").val("剩余"+res.vipInfo.remainTime+"次消费")
                                    }else {
                                        //其他会员等级的卡
                                        $(".vipSum").val("剩余"+res.vipInfo.balance+"元")
                                    }

                                }

                                function searchInfo() {
                                    var type = $("#searchType").val();
                                    var content = $("#searchContent").val();
                                    if (checkValue(type, content)) {
                                        var data = new FormData();
                                        data.append("type", type);
                                        data.append("content", content);
                                        var URL = "/process/search";
                                        $.ajax({
                                            url: URL,
                                            type: 'POST',
                                            cache: false,
                                            data: data,
                                            async:false,
                                            processData: false,
                                            contentType: false
                                        }).done(function (res) {
                                            console.log(res);
                                            $("#info").empty();
                                            for (var i=0;i<res.length;i++){
                                                var tmp =res[i];
                                                setValue(tmp);
                                                $("#info").prepend("<li><a class='searchOne' href=\"javascript:findOne("+tmp.userInfo.id+");\">" +"宝宝姓名："+ tmp.babyInfo.babyName +"&emsp;父母姓名："+tmp.userInfo.userName+"&emsp;会员卡号："+tmp.vipInfo.vipNo+ "&emsp;电话号码：" + tmp.userInfo.userTel + "</a></li>");
                                            }
                                            console.log(res);
                                        }).fail(function (res) {
                                            console.log(res);
                                            alert("数据异常")
                                        });
                                    }

                               //     console.log(type + "===" + content);

                                }


                               function findOne(id) {
                                   var data = new FormData();
                                   data.append("uid", id);
                                   var URL = "/process/one";
                                   $.ajax({
                                       url: URL,
                                       type: 'POST',
                                       cache: false,
                                       data: data,
                                       async:false,
                                       processData: false,
                                       contentType: false
                                   }).done(function (res) {
                                       console.log(res);
                                       $("#info").empty();
                                       if (res === null || res === undefined || res === '') {
                                           alert("该用户数据异常")
                                       }else {
                                           setValue(res);
                                       }
                                   }).fail(function (res) {
                                       console.log(res);
                                       alert("网络错误，请重新操作")
                                   });
                               }
                                // $("ul#info").on("click","li",function(){      //只需要找到你点击的是哪个ul里面的就行
                                //     alert("点击事件");
                                // });
                                function insertcase() {
                                    var URL = "/illCaseController/InsertSecondCase";
                                    var bid = $("#babyId").val();
                                    var uid = $("#userId").val();
                                    var data = new FormData();
                                    data.append("userId", uid);
                                    data.append("babyId", bid);
                                    data.append("illCaseState",0);
                                    $.ajax(
                                        {
                                            url: URL,
                                            type: 'POST',
                                            cache: false,
                                            data: data,
                                            async: false,
                                            processData: false,
                                            contentType: false
                                        }).done(function (res) {
                                        console.log(res.data);
                                        if (res === null || res === undefined || res === '') {
                                            alert("该用户数据异常")
                                        } else {
                                            window.location.href ="/illCaseController/getillcase?status=0"
                                        }
                                    }).fail(function (res) {
                                        console.log(res);
                                        alert("网络错误，请重新操作")
                                    });



                                }
                            </script>

                            <!-- 用户数据显示 -->
                            <div class="am-u-sm-12  am-u-md-12 am-u-lg-12" style="margin-top: 30px">
                                <ul id="info" class="am-list am-list-border">

                                </ul>
                            </div>
                            <div class="am-u-sm-12  am-u-md-12 am-u-lg-12" style="margin-top: 30px">

                                <%--会员卡类型--%>
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">会员卡类型</label>
                                    <div class="am-u-sm-7">
                                        <input type="hidden" name="babyId" id="babyId">
                                        <input type="hidden" name="userId" id="userId">
                                        <input  type="text" name="vipcategory" class="am-form-field tpl-form-no-bg vipcategory"
                                                placeholder="" maxlength="11" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                        <%--<small class="tipFileNo"></small>--%>
                                    </div>
                                </div>
                                <%--会员卡号码--%>
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">会员卡号</label>
                                    <div class="am-u-sm-7">
                                        <input  type="text" name="vipNo" class="am-form-field tpl-form-no-bg vipNo"
                                                placeholder="" maxlength="11" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                        <%--<small class="tipFileNo"></small>--%>
                                    </div>
                                </div>

                                <!-- 父母姓名-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">父母姓名</label>
                                    <div class="am-u-sm-7">
                                        <input  type="text" name="pname" class="am-form-field tpl-form-no-bg pname"
                                               placeholder="" maxlength="11" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>
                                <!-- 父母电话号码-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">电话号码</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" name="phone" class="am-form-field tpl-form-no-bg phone"
                                               placeholder="" maxlength="11" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>
                                <!-- 纸质档案编号-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">纸质档案编号</label>
                                    <div class="am-u-sm-7">
                                        <input id="fileNo" type="text" name="fileNo" class="am-form-field tpl-form-no-bg fileNo"
                                               placeholder="" maxlength="11" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 宝宝姓名-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">宝宝姓名</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" name="babyName" class="am-form-field tpl-form-no-bg babyName"
                                               placeholder="" maxlength="4" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 宝宝照片 -->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">宝宝照片</label>
                                    <div class="am-form-group am-u-sm-7">
                                        <div class="am-u-sm-5">
                                            <img class="am-u-sm-12 imagePhoto"  style="width: 90px; height: 80px;"
                                                 alt="未上传">
                                        </div>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 宝宝性别===性别校验-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-md-2 am-u-lg-3 am-form-label">宝宝性别</label>
                                    <div class="am-u-md-4 am-u-lg-7">
                                        <div class="am-u-sm-12">
                                            <select class="babySex"  name="babySex"
                                                    data-am-selected="{btnSize: 'sm'}">
                                                <option value="1">男</option>
                                                <option value="0">女</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="am-u-md-1 am-u-lg-2">
                                    </div>

                                    <label class="am-u-md-2 am-u-lg-3 am-form-label">是否早产</label>
                                    <div class="am-u-md-2 am-u-lg-7">
                                        <div class="am-form-group">
                                            <label class="am-radio-inline">
                                                <input type="radio" name="premature" class="premature" value="1"
                                                       readonly> 是
                                            </label>
                                            <label class="am-radio-inline">
                                                <input type="radio" name="premature" class="premature" checked="checked"
                                                       value="0" readonly> 否
                                            </label>
                                        </div>
                                    </div>

                                    <div class="am-u-md-1 am-u-lg-2">
                                    </div>
                                </div>

                                <!-- 宝宝年龄-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">宝宝年龄</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" name="babyAge" class="am-form-field tpl-form-no-bg babyAge"
                                               placeholder="" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 宝宝体重-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">宝宝体重</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" name="babyWeight"
                                               class="am-form-field tpl-form-no-bg babyWeight"
                                               placeholder="" maxlength="4" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 宝宝身高-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">宝宝身高</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" name="babyHeight"
                                               class="am-form-field tpl-form-no-bg babyHeight"
                                               placeholder="" maxlength="3" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 出生日期 -->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">出生日期</label>
                                    <div class="am-u-sm-7">
                                        <input type="text" class="am-form-field tpl-form-no-bg birthday" readonly/>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 喂养史-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">喂养史</label>
                                    <div class="am-u-sm-7">
                                    <textarea name="feedHistory" class="am-form-field tpl-form-no-bg feedHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 过敏史-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">过敏史</label>
                                    <div class="am-u-sm-7">
                                    <textarea name="allergyHistory" class="am-form-field tpl-form-no-bg allergyHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 病史-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">病史</label>
                                    <div class="am-u-sm-7">
                                    <textarea name="sickHistory" class="am-form-field tpl-form-no-bg sickHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>
                                    <%--卡余额或者剩余次数--%>
                                    <div class="am-form-group am-u-md-12 am-u-lg-6">
                                        <label class="am-u-sm-3 am-form-label">消费计数:</label>
                                        <div class="am-u-sm-7">
                                            <input  type="text" class="am-form-field tpl-form-no-bg vipSum"
                                                    placeholder="" maxlength="11" readonly/>
                                        </div>
                                        <div class="am-u-sm-2">
                                        </div>
                                    </div>

                                <!-- 备注-->
                                <div class="am-form-group am-u-md-12 am-u-lg-6">
                                    <label class="am-u-sm-3 am-form-label">备注</label>
                                    <div class="am-u-sm-7">
                                    <textarea id="notes" name="babyNote" class="am-form-field tpl-form-no-bg babyNote"
                                              placeholder="" maxlength="200" readonly></textarea>
                                    </div>
                                    <div class="am-u-sm-2">
                                    </div>
                                </div>

                                <!-- 按钮 -->
                                <div class="am-form-group am-u-md-12 am-u-lg-12">
                                    <span class="am-u-sm-3">
                                    </span>
                                    <div class="am-u-sm-7 am-u-sm-push-5">
                                        <%--<button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success am-u-sm-5" data-am-modal-close="">取消</button>
                                        <span class="am-u-sm-2">
                                        </span>--%>
                                        <button type="button" id="submitAddBaby" onclick="insertcase()"
                                                class="am-btn am-btn-primary tpl-btn-bg-color-success am-u-sm-5">下一步
                                        </button>
                                    </div>
                                    <span class="am-u-sm-2">
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="/resources/js/amazeui.min.js"></script>
<script src="/resources/js/amazeui.datatables.min.js"></script>
<script src="/resources/js/dataTables.responsive.min.js"></script>
<script src="/resources/js/app.js"></script>

</body>
</html>